package com.yykj.user.center.server.controller.patient;

import com.yykj.common.vo.PageData;
import com.yykj.common.vo.ResultVO;
import com.yykj.user.center.server.dto.RegisteredOrderDTO;
import com.yykj.user.center.server.form.AppointmentForm;
import com.yykj.user.center.server.form.CancelAppointmentForm;
import com.yykj.user.center.server.service.patient.RegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author chenl
 * @version 1.0
 * @date 2021/10/30 22:05
 */
@Slf4j
@Api(tags = "挂号相关接口")
@RestController
@RequestMapping("/api/register")
@SuppressWarnings("unchecked")
public class RegisterController {

    @Autowired
    private RegisterService registerService;


    @PostMapping("/create")
    @ApiOperation("预约挂号")
    public ResultVO create(@Valid @RequestBody AppointmentForm appointmentForm) {
        return ResultVO.success(registerService.create(appointmentForm));
    }


    @PostMapping("/cancel")
    @ApiOperation("取消预约挂号")
    public ResultVO cancel(@Valid @RequestBody CancelAppointmentForm cancelAppointmentForm) {
        return ResultVO.success(registerService.cancel(cancelAppointmentForm));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "每页显示的条数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "startDate", value = "开始日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "patientName", value = "预约人", required = false, dataType = "String"),
            @ApiImplicitParam(name = "doctorName", value = "预约医生", required = false, dataType = "String"),
            @ApiImplicitParam(name = "patientCardId", value = "就诊卡ID", required = false, dataType = "String"),
            @ApiImplicitParam(name = "state", value = "状态 1待就诊 2已就诊 3已取消", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "hospitalId", value = "医院Id", required = false, dataType = "Integer"),
    })
    @ApiOperation(value = "预约挂号列表", notes = "预约挂号列表")
    @GetMapping("/list")
    public ResultVO<PageData<RegisteredOrderDTO>> list(@RequestParam(value = "current", required = false,defaultValue = "1") Integer current,
                                                       @RequestParam(value = "size", required = false,defaultValue = "20") Integer size,
                                                       @RequestParam(value = "startDate", required = false) String startDate,
                                                       @RequestParam(value = "endDate", required = false) String endDate,
                                                       @RequestParam(value = "patientName", required = false) String patientName,
                                                       @RequestParam(value = "doctorName", required = false) String doctorName,
                                                       @RequestParam(value = "patientCardId", required = false) String patientCardId,
                                                       @RequestParam(value = "state", required = false) Integer state,
                                                       @RequestParam(value = "hospitalId", required = false) Integer hospitalId) {
        return ResultVO.success(registerService.list(current,size,startDate,endDate,patientName,doctorName,patientCardId, state,hospitalId));
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "每页显示的条数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "startDate", value = "开始日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "patientName", value = "预约人", required = false, dataType = "String"),
            @ApiImplicitParam(name = "doctorName", value = "预约医生", required = false, dataType = "String"),
            @ApiImplicitParam(name = "patientCardId", value = "就诊卡ID", required = false, dataType = "String"),
            @ApiImplicitParam(name = "state", value = "状态 1待就诊 2已就诊 3已取消", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "hospitalId", value = "医院Id", required = false, dataType = "Integer"),
    })
    @ApiOperation(value = "预约挂号列表:后台管理用", notes = "预约挂号列表")
    @GetMapping("/admin/list")
    public ResultVO<PageData<RegisteredOrderDTO>> adminList(@RequestParam(value = "current", required = false,defaultValue = "1") Integer current,
                         @RequestParam(value = "size", required = false,defaultValue = "20") Integer size,
                         @RequestParam(value = "startDate", required = false) String startDate,
                         @RequestParam(value = "endDate", required = false) String endDate,
                         @RequestParam(value = "patientName", required = false) String patientName,
                         @RequestParam(value = "doctorName", required = false) String doctorName,
                         @RequestParam(value = "patientCardId", required = false) String patientCardId,
                         @RequestParam(value = "state", required = false) Integer state,
                         @RequestParam(value = "hospitalId", required = false) Integer hospitalId) {
        return ResultVO.success(registerService.adminList(current,size,startDate,endDate,patientName,doctorName,patientCardId, state,hospitalId));
    }

}
